package day17_Inet.demo08_TCP;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class Clien_TCP {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        Socket socket = new Socket("192.168.3.172", 8888);
       while (true){
           //发送数据
           OutputStream os = socket.getOutputStream();
           String s = scanner.next();
           os.write(s.getBytes());
           if (s.equals("bye")){
               break;
           }
           //接收数据
           InputStream is = socket.getInputStream();
           byte[] bytes = new byte[1024];
           int i = is.read(bytes);
           String s1 = new String(bytes, 0, i);
           System.out.println("接收的数据为"+s1);
           if (s1.equals("bye")){
               break;
           }
       }
        socket.close();
    }
}
